export { store } from '@/store'
export { routerArrays } from '@/layout/type'
export { getConfig, responsiveStorageNameSpace } from '@/config'

export type { UserStoreType, setType, multiType, positionType } from './types'
export function storageLocal() {
  return {
    // 获取指定键的值
    getItem<T>(key: string): T | null {
      const item = localStorage.getItem(key)
      if (item) {
        try {
          return JSON.parse(item) as T
        } catch (error) {
          // 如果解析失败，返回原始字符串
          return item as unknown as T
        }
      }
      return null
    },

    // 设置指定键的值
    setItem<T>(key: string, value: T): void {
      if (typeof value === 'string') {
        localStorage.setItem(key, value)
      } else {
        localStorage.setItem(key, JSON.stringify(value))
      }
    },

    removeItem(key: string): void {
      localStorage.removeItem(key)
    },

    // 清除所有存储项
    clear(): void {
      localStorage.clear()
    }
  }
}

export function isObject(obj: unknown): obj is Record<string, unknown> {
  return obj !== null && typeof obj === 'object'
}
